{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/tuan/Works/h1st/.venv/lib/python3.10/site-packages/tqdm/auto.py:22: TqdmWarning:\n",
      "\n",
      "IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from h1st.model.predictive_model import PredictiveModel\n",
    "import pandas as pd\n",
    "\n",
    "class RuleModel(PredictiveModel):\n",
    "    sepal_length_max: float = 5.3\n",
    "    sepal_length_min: float = 3.7\n",
    "    sepal_width_max: float = 4.4\n",
    "    sepal_width_min: float = 3\n",
    "    \n",
    "    def predict(self, data):\n",
    "        df = data['X']\n",
    "        return {'predictions': pd.DataFrame(\n",
    "            map(self.predict_setosa, df['sepal_length'], df['sepal_width']), \n",
    "            columns=['setosa'])}\n",
    "\n",
    "    def predict_setosa(self, sepal_length, sepal_width):\n",
    "        return 1 if (self.sepal_length_min <= sepal_length <= self.sepal_length_max) \\\n",
    "                  & (self.sepal_width_min <= sepal_width <= self.sepal_width_max) \\\n",
    "               else 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from h1st.model.fuzzy import (\n",
    "    FuzzyVariables,\n",
    "    FuzzyMembership as fm,\n",
    "    FuzzyRules,\n",
    "    FuzzyModeler\n",
    ")\n",
    "\n",
    "def get_metadata(data):\n",
    "    res = {}\n",
    "    for k, v in data.max().to_dict().items():\n",
    "        res[k] = {'max': v}\n",
    "    for k, v in data.min().to_dict().items():\n",
    "        res[k].update({'min': v})    \n",
    "    return res\n",
    "\n",
    "def create_fuzzy_model(data):\n",
    "    metadata = get_metadata(data)\n",
    "    fuzzy_vars = FuzzyVariables()\n",
    "    fuzzy_vars.add(\n",
    "        var_name='sepal_length',\n",
    "        var_type='antecedent',\n",
    "        var_range=np.arange(\n",
    "            metadata['sepal_length']['min'], \n",
    "            metadata['sepal_length']['max'], \n",
    "            0.1\n",
    "        ),\n",
    "        membership_funcs=[('small', fm.SIGMOID, [5.3, -2.5]),\n",
    "                            ('large', fm.SIGMOID, [5.3, 2.5])]\n",
    "    )\n",
    "    fuzzy_vars.add(\n",
    "        var_name='sepal_width',\n",
    "        var_type='antecedent',\n",
    "        var_range=np.arange(\n",
    "            metadata['sepal_width']['min'], \n",
    "            metadata['sepal_width']['max'], \n",
    "            0.1\n",
    "        ),\n",
    "        membership_funcs=[('small', fm.SIGMOID, [3.1, -2.0]),\n",
    "                            ('large', fm.SIGMOID, [3.1, 2.0])]\n",
    "    )\n",
    "    fuzzy_vars.add(\n",
    "        var_name='setosa',\n",
    "        var_type='consequent',\n",
    "        var_range=np.arange(0, 1+1e-5, 0.1),\n",
    "        membership_funcs=[('false', fm.GAUSSIAN, [0, 0.5]),\n",
    "                        ('true', fm.GAUSSIAN, [1, 0.5])]\n",
    "    )\n",
    "\n",
    "    fuzzy_rule = FuzzyRules()\n",
    "    fuzzy_rule.add(\n",
    "        'rule1',\n",
    "        if_term=fuzzy_vars.get('sepal_length')['small'] & fuzzy_vars.get('sepal_width')['large'],\n",
    "        then_term=fuzzy_vars.get('setosa')['true']\n",
    "    )\n",
    "    fuzzy_rule.add(\n",
    "        'rule2',\n",
    "        if_term=fuzzy_vars.get('sepal_length')['large'] & fuzzy_vars.get('sepal_width')['small'],\n",
    "        then_term=fuzzy_vars.get('setosa')['false']\n",
    "    )\n",
    "\n",
    "    modeler = FuzzyModeler()\n",
    "    teacher = modeler.build_model(fuzzy_vars, fuzzy_rule)\n",
    "    return teacher"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_raw = datasets.load_iris(as_frame=True).frame\n",
    "df_raw.columns = [\n",
    "    \"sepal_length\",\n",
    "    \"sepal_width\",\n",
    "    \"petal_length\",\n",
    "    \"petal_width\",\n",
    "    \"setosa\",\n",
    "]\n",
    "df_raw = df_raw[[\n",
    "    \"sepal_length\",\n",
    "    \"sepal_width\",\n",
    "    \"setosa\"]]\n",
    "df_raw[\"setosa\"] = df_raw[\"setosa\"].apply(lambda x: 1 if x == 0 else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    100\n",
       "1     50\n",
       "Name: setosa, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "df_raw[\"setosa\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2022-10-08 16:56:33.953 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:34.220 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "2022-10-08 16:56:34.559 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "2022-10-08 16:56:34.895 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:35.208 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:35.523 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:35.524 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.78571, 'students': [0.78571, 0.9375], 'ensemblers': 0.78571}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.64706, 'students': [0.64706, 0.88235], 'ensemblers': 0.64706}}}\n",
      "2022-10-08 16:56:35.525 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.82759, 'students': [0.78571, 0.90323], 'ensemblers': 0.78571}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.70588, 'students': [0.64706, 0.82353], 'ensemblers': 0.64706}}}\n",
      "2022-10-08 16:56:35.525 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.78571, 'students': [0.78571, 0.9375], 'ensemblers': 1.0}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.64706, 'students': [0.64706, 0.88235], 'ensemblers': 1.0}}}\n",
      "2022-10-08 16:56:35.526 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.82759, 'students': [0.78571, 0.90323], 'ensemblers': 1.0}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.70588, 'students': [0.64706, 0.82353], 'ensemblers': 1.0}}}\n",
      "2022-10-08 16:56:35.526 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.78571, 'students': [0.78571, 0.9375], 'ensemblers': 1.0}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.64706, 'students': [0.64706, 0.88235], 'ensemblers': 1.0}}}\n",
      "2022-10-08 16:56:35.527 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.82759, 'students': [0.78571, 0.90323], 'ensemblers': 1.0}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.70588, 'students': [0.64706, 0.82353], 'ensemblers': 1.0}}}\n",
      "2022-10-08 16:56:35.735 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:35.982 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "2022-10-08 16:56:36.291 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "2022-10-08 16:56:36.760 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:37.062 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:37.390 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:37.391 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.92308, 'students': [0.92308, 0.92308], 'ensemblers': 0.92308}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.85714, 'students': [0.85714, 0.85714], 'ensemblers': 0.85714}}}\n",
      "2022-10-08 16:56:37.392 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.92308, 'students': [0.96296, 0.96296], 'ensemblers': 0.96296}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.85714, 'students': [0.92857, 0.92857], 'ensemblers': 0.92857}}}\n",
      "2022-10-08 16:56:37.393 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.92308, 'students': [0.92308, 0.92308], 'ensemblers': 1.0}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.85714, 'students': [0.85714, 0.85714], 'ensemblers': 1.0}}}\n",
      "2022-10-08 16:56:37.393 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.92308, 'students': [0.96296, 0.96296], 'ensemblers': 1.0}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.85714, 'students': [0.92857, 0.92857], 'ensemblers': 1.0}}}\n",
      "2022-10-08 16:56:37.394 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.92308, 'students': [0.92308, 0.92308], 'ensemblers': 1.0}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.85714, 'students': [0.85714, 0.85714], 'ensemblers': 1.0}}}\n",
      "2022-10-08 16:56:37.394 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.92308, 'students': [0.96296, 0.96296], 'ensemblers': 1.0}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.85714, 'students': [0.92857, 0.92857], 'ensemblers': 1.0}}}\n",
      "2022-10-08 16:56:37.609 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:37.867 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "2022-10-08 16:56:38.327 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "X has feature names, but StandardScaler was fitted without feature names\n",
      "2022-10-08 16:56:38.691 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:38.992 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:39.309 | INFO     | h1st.model.oracle.oracle_modeler:build_model:142 - Evaluated all sub models successfully.\n",
      "2022-10-08 16:56:39.311 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.88235, 'students': [0.91429, 0.94444], 'ensemblers': 0.91429}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.78947, 'students': [0.84211, 0.89474], 'ensemblers': 0.84211}}}\n",
      "2022-10-08 16:56:39.312 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.84848, 'students': [0.91429, 0.97297], 'ensemblers': 0.91429}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.73684, 'students': [0.84211, 0.94737], 'ensemblers': 0.84211}}}\n",
      "2022-10-08 16:56:39.312 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.88235, 'students': [0.91429, 0.94444], 'ensemblers': 1.0}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.78947, 'students': [0.84211, 0.89474], 'ensemblers': 1.0}}}\n",
      "2022-10-08 16:56:39.313 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.84848, 'students': [0.91429, 0.97297], 'ensemblers': 0.95}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 0.90476}}, 'recall': {'setosa': {'teacher': 0.73684, 'students': [0.84211, 0.94737], 'ensemblers': 1.0}}}\n",
      "2022-10-08 16:56:39.313 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.88235, 'students': [0.91429, 0.94444], 'ensemblers': 0.97297}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.78947, 'students': [0.84211, 0.89474], 'ensemblers': 0.94737}}}\n",
      "2022-10-08 16:56:39.314 | INFO     | __main__:<module>:89 - {'f1_score': {'setosa': {'teacher': 0.84848, 'students': [0.91429, 0.97297], 'ensemblers': 0.97297}}, 'precision': {'setosa': {'teacher': 1.0, 'students': [1.0, 1.0], 'ensemblers': 1.0}}, 'recall': {'setosa': {'teacher': 0.73684, 'students': [0.84211, 0.94737], 'ensemblers': 0.94737}}}\n"
     ]
    }
   ],
   "source": [
    "from collections import defaultdict\n",
    "from numpy import array\n",
    "from sklearn.model_selection import KFold\n",
    "from h1st.model.oracle import OracleModeler\n",
    "from h1st.model.oracle.ensembler_modelers import MLPEnsembleModeler\n",
    "from loguru import logger\n",
    "\n",
    "# prepare cross validation\n",
    "kfold = KFold(n_splits=3, shuffle=True, random_state=1)\n",
    "\n",
    "all_metrics = defaultdict(lambda: defaultdict(list))\n",
    "all_index = defaultdict(lambda: defaultdict(list))\n",
    "\n",
    "# 1. build rule-based model\n",
    "bool_teacher = RuleModel()\n",
    "fuzzy_teacher = create_fuzzy_model(df_raw)\n",
    "\n",
    "# enumerate splits\n",
    "for no, data_idx in enumerate(kfold.split(df_raw)):\n",
    "    train, test = data_idx\n",
    "    # 2. prepare data\n",
    "    df_train, df_test = df_raw.iloc[train], df_raw.iloc[test]\n",
    "    input_data = {\n",
    "        \"unlabeled_data\": df_train[[\"sepal_length\", \"sepal_width\"]],\n",
    "        \"labeled_data\": {\n",
    "            \"X_train\": df_train[[\"sepal_length\", \"sepal_width\"]],\n",
    "            \"y_train\": df_train[[\"setosa\"]],\n",
    "            \"X_test\": df_test[[\"sepal_length\", \"sepal_width\"]],\n",
    "            \"y_test\": df_test[[\"setosa\"]],\n",
    "        },\n",
    "    }\n",
    "\n",
    "    # 3. build oracle\n",
    "    # 3.1 bool\n",
    "    modeler = OracleModeler()\n",
    "    oracle_with_bool = modeler.build_model(\n",
    "        data=input_data,\n",
    "        teacher_model=bool_teacher\n",
    "    )\n",
    "    \n",
    "    # 3.2 fuzzy\n",
    "    fuzzy_thresholds = {'setosa': 0.55}\n",
    "    oracle_with_fuzzy = modeler.build_model(\n",
    "        data=input_data,\n",
    "        teacher_model=fuzzy_teacher,\n",
    "        fuzzy_thresholds=fuzzy_thresholds)\n",
    "\n",
    "    # 3.3 bool + ml_ensemble\n",
    "    oracle_with_bool_ml = modeler.build_model(\n",
    "        data=input_data, \n",
    "        teacher_model=bool_teacher,\n",
    "        ensembler_modeler=MLPEnsembleModeler)\n",
    "\n",
    "    # 3.4 fuzzy + ml_ensemble\n",
    "    fuzzy_thresholds = {'setosa': 0.55}\n",
    "    oracle_with_fuzzy_ml = modeler.build_model(\n",
    "        data=input_data, \n",
    "        teacher_model=fuzzy_teacher,\n",
    "        fuzzy_thresholds=fuzzy_thresholds,\n",
    "        ensembler_modeler=MLPEnsembleModeler) \n",
    "\n",
    "    # 3.5 bool + ml_ensemble + x\n",
    "    oracle_with_bool_ml_x = modeler.build_model(\n",
    "        data=input_data, \n",
    "        teacher_model=bool_teacher,\n",
    "        ensembler_modeler=MLPEnsembleModeler,\n",
    "        inject_x_in_ensembler=True)\n",
    "\n",
    "    # # 3.6 fuzzy + ml_ensemble + x\n",
    "    fuzzy_thresholds = {'setosa': 0.55}\n",
    "    oracle_with_fuzzy_ml_x = modeler.build_model(\n",
    "        data=input_data, \n",
    "        teacher_model=fuzzy_teacher,\n",
    "        fuzzy_thresholds=fuzzy_thresholds,\n",
    "        ensembler_modeler=MLPEnsembleModeler,\n",
    "        inject_x_in_ensembler=True) \n",
    "\n",
    "    model_map = {\n",
    "        \"oracle_with_bool\": oracle_with_bool,\n",
    "        \"oracle_with_fuzzy\": oracle_with_fuzzy,\n",
    "        \"oracle_with_bool_ml\": oracle_with_bool_ml,\n",
    "        \"oracle_with_fuzzy_ml\": oracle_with_fuzzy_ml,\n",
    "        \"oracle_with_bool_ml_x\": oracle_with_bool_ml_x,\n",
    "        \"oracle_with_fuzzy_ml_x\": oracle_with_fuzzy_ml_x,        \n",
    "    }\n",
    "\n",
    "    # 4. collect evaluation results\n",
    "    for name, oracle in model_map.items():\n",
    "        logger.info(oracle.metrics)\n",
    "        for metrics in ['f1_score', 'precision', 'recall']:\n",
    "            temp = oracle.metrics[metrics]['setosa']\n",
    "            s1, s2 = temp.pop('students')\n",
    "            temp.update({'student1': s1, 'student2': s2})\n",
    "            all_metrics[metrics][name].append(temp)\n",
    "            all_index[metrics][name].append(f'{name}_{no}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>metrics_type</th>\n",
       "      <th>teacher</th>\n",
       "      <th>ensemblers</th>\n",
       "      <th>student1</th>\n",
       "      <th>student2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>oracle_with_bool</th>\n",
       "      <td>f1_score</td>\n",
       "      <td>0.863713</td>\n",
       "      <td>0.874360</td>\n",
       "      <td>0.874360</td>\n",
       "      <td>0.935007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_fuzzy</th>\n",
       "      <td>f1_score</td>\n",
       "      <td>0.866383</td>\n",
       "      <td>0.887653</td>\n",
       "      <td>0.887653</td>\n",
       "      <td>0.946387</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_bool_ml</th>\n",
       "      <td>f1_score</td>\n",
       "      <td>0.863713</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.874360</td>\n",
       "      <td>0.935007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_fuzzy_ml</th>\n",
       "      <td>f1_score</td>\n",
       "      <td>0.866383</td>\n",
       "      <td>0.983333</td>\n",
       "      <td>0.887653</td>\n",
       "      <td>0.946387</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_bool_ml_x</th>\n",
       "      <td>f1_score</td>\n",
       "      <td>0.863713</td>\n",
       "      <td>0.990990</td>\n",
       "      <td>0.874360</td>\n",
       "      <td>0.935007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_fuzzy_ml_x</th>\n",
       "      <td>f1_score</td>\n",
       "      <td>0.866383</td>\n",
       "      <td>0.990990</td>\n",
       "      <td>0.887653</td>\n",
       "      <td>0.946387</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_bool</th>\n",
       "      <td>precision</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_fuzzy</th>\n",
       "      <td>precision</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_bool_ml</th>\n",
       "      <td>precision</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_fuzzy_ml</th>\n",
       "      <td>precision</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.968253</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_bool_ml_x</th>\n",
       "      <td>precision</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_fuzzy_ml_x</th>\n",
       "      <td>precision</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_bool</th>\n",
       "      <td>recall</td>\n",
       "      <td>0.764557</td>\n",
       "      <td>0.782103</td>\n",
       "      <td>0.782103</td>\n",
       "      <td>0.878077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_fuzzy</th>\n",
       "      <td>recall</td>\n",
       "      <td>0.766620</td>\n",
       "      <td>0.805913</td>\n",
       "      <td>0.805913</td>\n",
       "      <td>0.899823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_bool_ml</th>\n",
       "      <td>recall</td>\n",
       "      <td>0.764557</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.782103</td>\n",
       "      <td>0.878077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_fuzzy_ml</th>\n",
       "      <td>recall</td>\n",
       "      <td>0.766620</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.805913</td>\n",
       "      <td>0.899823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_bool_ml_x</th>\n",
       "      <td>recall</td>\n",
       "      <td>0.764557</td>\n",
       "      <td>0.982457</td>\n",
       "      <td>0.782103</td>\n",
       "      <td>0.878077</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>oracle_with_fuzzy_ml_x</th>\n",
       "      <td>recall</td>\n",
       "      <td>0.766620</td>\n",
       "      <td>0.982457</td>\n",
       "      <td>0.805913</td>\n",
       "      <td>0.899823</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       metrics_type   teacher  ensemblers  student1  student2\n",
       "oracle_with_bool           f1_score  0.863713    0.874360  0.874360  0.935007\n",
       "oracle_with_fuzzy          f1_score  0.866383    0.887653  0.887653  0.946387\n",
       "oracle_with_bool_ml        f1_score  0.863713    1.000000  0.874360  0.935007\n",
       "oracle_with_fuzzy_ml       f1_score  0.866383    0.983333  0.887653  0.946387\n",
       "oracle_with_bool_ml_x      f1_score  0.863713    0.990990  0.874360  0.935007\n",
       "oracle_with_fuzzy_ml_x     f1_score  0.866383    0.990990  0.887653  0.946387\n",
       "oracle_with_bool          precision  1.000000    1.000000  1.000000  1.000000\n",
       "oracle_with_fuzzy         precision  1.000000    1.000000  1.000000  1.000000\n",
       "oracle_with_bool_ml       precision  1.000000    1.000000  1.000000  1.000000\n",
       "oracle_with_fuzzy_ml      precision  1.000000    0.968253  1.000000  1.000000\n",
       "oracle_with_bool_ml_x     precision  1.000000    1.000000  1.000000  1.000000\n",
       "oracle_with_fuzzy_ml_x    precision  1.000000    1.000000  1.000000  1.000000\n",
       "oracle_with_bool             recall  0.764557    0.782103  0.782103  0.878077\n",
       "oracle_with_fuzzy            recall  0.766620    0.805913  0.805913  0.899823\n",
       "oracle_with_bool_ml          recall  0.764557    1.000000  0.782103  0.878077\n",
       "oracle_with_fuzzy_ml         recall  0.766620    1.000000  0.805913  0.899823\n",
       "oracle_with_bool_ml_x        recall  0.764557    0.982457  0.782103  0.878077\n",
       "oracle_with_fuzzy_ml_x       recall  0.766620    0.982457  0.805913  0.899823"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "all_avg_metrics = []\n",
    "oracle_names = []\n",
    "for metrics_type in ['f1_score', 'precision', 'recall']:\n",
    "    for oracle_name, metrics in all_metrics[metrics_type].items():\n",
    "        df_metrics = pd.DataFrame(metrics)\n",
    "        # print(metrics_type, oracle_name, df_metrics.mean().values)\n",
    "        all_avg_metrics.append(\n",
    "            [metrics_type] + list(df_metrics.mean().values)\n",
    "        )\n",
    "        oracle_names.append(oracle_name)\n",
    "\n",
    "final_metrics = pd.DataFrame(\n",
    "    all_avg_metrics,\n",
    "    columns=['metrics_type', 'teacher', 'ensemblers', 'student1', 'student2'],\n",
    "    index=oracle_names\n",
    ")\n",
    "\n",
    "final_metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "final_metrics.to_csv('iris_eval_results.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "hovertemplate": "<b>SepalWidthCm:</b> %{x} <br><b>SepalLengthCm:</b> %{y}",
         "marker": {
          "color": "rgb(52, 152, 219)",
          "line": {
           "width": 1.5
          },
          "opacity": 0.8,
          "size": 12,
          "symbol": "star-triangle-up"
         },
         "mode": "markers",
         "name": "Setosa",
         "type": "scatter",
         "x": [
          3.5,
          3,
          3.2,
          3.1,
          3.6,
          3.9,
          3.4,
          3.4,
          2.9,
          3.1,
          3.7,
          3.4,
          3,
          3,
          4,
          4.4,
          3.9,
          3.5,
          3.8,
          3.8,
          3.4,
          3.7,
          3.6,
          3.3,
          3.4,
          3,
          3.4,
          3.5,
          3.4,
          3.2,
          3.1,
          3.4,
          4.1,
          4.2,
          3.1,
          3.2,
          3.5,
          3.6,
          3,
          3.4,
          3.5,
          2.3,
          3.2,
          3.5,
          3.8,
          3,
          3.8,
          3.2,
          3.7,
          3.3
         ],
         "y": [
          5.1,
          4.9,
          4.7,
          4.6,
          5,
          5.4,
          4.6,
          5,
          4.4,
          4.9,
          5.4,
          4.8,
          4.8,
          4.3,
          5.8,
          5.7,
          5.4,
          5.1,
          5.7,
          5.1,
          5.4,
          5.1,
          4.6,
          5.1,
          4.8,
          5,
          5,
          5.2,
          5.2,
          4.7,
          4.8,
          5.4,
          5.2,
          5.5,
          4.9,
          5,
          5.5,
          4.9,
          4.4,
          5.1,
          5,
          4.5,
          4.4,
          5,
          5.1,
          4.8,
          5.1,
          4.6,
          5.3,
          5
         ]
        },
        {
         "hovertemplate": "<b>SepalWidthCm:</b> %{x} <br><b>SepalLengthCm:</b> %{y}",
         "marker": {
          "color": "rgb(170, 128, 255)",
          "line": {
           "width": 1.5
          },
          "opacity": 0.8,
          "size": 12,
          "symbol": "hexagram"
         },
         "mode": "markers",
         "name": "Non-Setosa",
         "type": "scatter",
         "x": [
          3.2,
          3.2,
          3.1,
          2.3,
          2.8,
          2.8,
          3.3,
          2.4,
          2.9,
          2.7,
          2,
          3,
          2.2,
          2.9,
          2.9,
          3.1,
          3,
          2.7,
          2.2,
          2.5,
          3.2,
          2.8,
          2.5,
          2.8,
          2.9,
          3,
          2.8,
          3,
          2.9,
          2.6,
          2.4,
          2.4,
          2.7,
          2.7,
          3,
          3.4,
          3.1,
          2.3,
          3,
          2.5,
          2.6,
          3,
          2.6,
          2.3,
          2.7,
          3,
          2.9,
          2.9,
          2.5,
          2.8,
          3.3,
          2.7,
          3,
          2.9,
          3,
          3,
          2.5,
          2.9,
          2.5,
          3.6,
          3.2,
          2.7,
          3,
          2.5,
          2.8,
          3.2,
          3,
          3.8,
          2.6,
          2.2,
          3.2,
          2.8,
          2.8,
          2.7,
          3.3,
          3.2,
          2.8,
          3,
          2.8,
          3,
          2.8,
          3.8,
          2.8,
          2.8,
          2.6,
          3,
          3.4,
          3.1,
          3,
          3.1,
          3.1,
          3.1,
          2.7,
          3.2,
          3.3,
          3,
          2.5,
          3,
          3.4,
          3
         ],
         "y": [
          7,
          6.4,
          6.9,
          5.5,
          6.5,
          5.7,
          6.3,
          4.9,
          6.6,
          5.2,
          5,
          5.9,
          6,
          6.1,
          5.6,
          6.7,
          5.6,
          5.8,
          6.2,
          5.6,
          5.9,
          6.1,
          6.3,
          6.1,
          6.4,
          6.6,
          6.8,
          6.7,
          6,
          5.7,
          5.5,
          5.5,
          5.8,
          6,
          5.4,
          6,
          6.7,
          6.3,
          5.6,
          5.5,
          5.5,
          6.1,
          5.8,
          5,
          5.6,
          5.7,
          5.7,
          6.2,
          5.1,
          5.7,
          6.3,
          5.8,
          7.1,
          6.3,
          6.5,
          7.6,
          4.9,
          7.3,
          6.7,
          7.2,
          6.5,
          6.4,
          6.8,
          5.7,
          5.8,
          6.4,
          6.5,
          7.7,
          7.7,
          6,
          6.9,
          5.6,
          7.7,
          6.3,
          6.7,
          7.2,
          6.2,
          6.1,
          6.4,
          7.2,
          7.4,
          7.9,
          6.4,
          6.3,
          6.1,
          7.7,
          6.3,
          6.4,
          6,
          6.9,
          6.7,
          6.9,
          5.8,
          6.8,
          6.7,
          6.7,
          6.3,
          6.5,
          6.2,
          5.9
         ]
        }
       ],
       "layout": {
        "template": {
         "data": {
          "bar": [
           {
            "error_x": {
             "color": "#2a3f5f"
            },
            "error_y": {
             "color": "#2a3f5f"
            },
            "marker": {
             "line": {
              "color": "white",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "bar"
           }
          ],
          "barpolar": [
           {
            "marker": {
             "line": {
              "color": "white",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "barpolar"
           }
          ],
          "carpet": [
           {
            "aaxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "#C8D4E3",
             "linecolor": "#C8D4E3",
             "minorgridcolor": "#C8D4E3",
             "startlinecolor": "#2a3f5f"
            },
            "baxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "#C8D4E3",
             "linecolor": "#C8D4E3",
             "minorgridcolor": "#C8D4E3",
             "startlinecolor": "#2a3f5f"
            },
            "type": "carpet"
           }
          ],
          "choropleth": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "choropleth"
           }
          ],
          "contour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "contour"
           }
          ],
          "contourcarpet": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "contourcarpet"
           }
          ],
          "heatmap": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmap"
           }
          ],
          "heatmapgl": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmapgl"
           }
          ],
          "histogram": [
           {
            "marker": {
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "histogram"
           }
          ],
          "histogram2d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2d"
           }
          ],
          "histogram2dcontour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2dcontour"
           }
          ],
          "mesh3d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "mesh3d"
           }
          ],
          "parcoords": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "parcoords"
           }
          ],
          "pie": [
           {
            "automargin": true,
            "type": "pie"
           }
          ],
          "scatter": [
           {
            "fillpattern": {
             "fillmode": "overlay",
             "size": 10,
             "solidity": 0.2
            },
            "type": "scatter"
           }
          ],
          "scatter3d": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatter3d"
           }
          ],
          "scattercarpet": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattercarpet"
           }
          ],
          "scattergeo": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergeo"
           }
          ],
          "scattergl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergl"
           }
          ],
          "scattermapbox": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermapbox"
           }
          ],
          "scatterpolar": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolar"
           }
          ],
          "scatterpolargl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolargl"
           }
          ],
          "scatterternary": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterternary"
           }
          ],
          "surface": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "surface"
           }
          ],
          "table": [
           {
            "cells": {
             "fill": {
              "color": "#EBF0F8"
             },
             "line": {
              "color": "white"
             }
            },
            "header": {
             "fill": {
              "color": "#C8D4E3"
             },
             "line": {
              "color": "white"
             }
            },
            "type": "table"
           }
          ]
         },
         "layout": {
          "annotationdefaults": {
           "arrowcolor": "#2a3f5f",
           "arrowhead": 0,
           "arrowwidth": 1
          },
          "autotypenumbers": "strict",
          "coloraxis": {
           "colorbar": {
            "outlinewidth": 0,
            "ticks": ""
           }
          },
          "colorscale": {
           "diverging": [
            [
             0,
             "#8e0152"
            ],
            [
             0.1,
             "#c51b7d"
            ],
            [
             0.2,
             "#de77ae"
            ],
            [
             0.3,
             "#f1b6da"
            ],
            [
             0.4,
             "#fde0ef"
            ],
            [
             0.5,
             "#f7f7f7"
            ],
            [
             0.6,
             "#e6f5d0"
            ],
            [
             0.7,
             "#b8e186"
            ],
            [
             0.8,
             "#7fbc41"
            ],
            [
             0.9,
             "#4d9221"
            ],
            [
             1,
             "#276419"
            ]
           ],
           "sequential": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ],
           "sequentialminus": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ]
          },
          "colorway": [
           "#636efa",
           "#EF553B",
           "#00cc96",
           "#ab63fa",
           "#FFA15A",
           "#19d3f3",
           "#FF6692",
           "#B6E880",
           "#FF97FF",
           "#FECB52"
          ],
          "font": {
           "color": "#2a3f5f"
          },
          "geo": {
           "bgcolor": "white",
           "lakecolor": "white",
           "landcolor": "white",
           "showlakes": true,
           "showland": true,
           "subunitcolor": "#C8D4E3"
          },
          "hoverlabel": {
           "align": "left"
          },
          "hovermode": "closest",
          "mapbox": {
           "style": "light"
          },
          "paper_bgcolor": "white",
          "plot_bgcolor": "white",
          "polar": {
           "angularaxis": {
            "gridcolor": "#EBF0F8",
            "linecolor": "#EBF0F8",
            "ticks": ""
           },
           "bgcolor": "white",
           "radialaxis": {
            "gridcolor": "#EBF0F8",
            "linecolor": "#EBF0F8",
            "ticks": ""
           }
          },
          "scene": {
           "xaxis": {
            "backgroundcolor": "white",
            "gridcolor": "#DFE8F3",
            "gridwidth": 2,
            "linecolor": "#EBF0F8",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "#EBF0F8"
           },
           "yaxis": {
            "backgroundcolor": "white",
            "gridcolor": "#DFE8F3",
            "gridwidth": 2,
            "linecolor": "#EBF0F8",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "#EBF0F8"
           },
           "zaxis": {
            "backgroundcolor": "white",
            "gridcolor": "#DFE8F3",
            "gridwidth": 2,
            "linecolor": "#EBF0F8",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "#EBF0F8"
           }
          },
          "shapedefaults": {
           "line": {
            "color": "#2a3f5f"
           }
          },
          "ternary": {
           "aaxis": {
            "gridcolor": "#DFE8F3",
            "linecolor": "#A2B1C6",
            "ticks": ""
           },
           "baxis": {
            "gridcolor": "#DFE8F3",
            "linecolor": "#A2B1C6",
            "ticks": ""
           },
           "bgcolor": "white",
           "caxis": {
            "gridcolor": "#DFE8F3",
            "linecolor": "#A2B1C6",
            "ticks": ""
           }
          },
          "title": {
           "x": 0.05
          },
          "xaxis": {
           "automargin": true,
           "gridcolor": "#EBF0F8",
           "linecolor": "#EBF0F8",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "#EBF0F8",
           "zerolinewidth": 2
          },
          "yaxis": {
           "automargin": true,
           "gridcolor": "#EBF0F8",
           "linecolor": "#EBF0F8",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "#EBF0F8",
           "zerolinewidth": 2
          }
         }
        },
        "title": {
         "text": "Sepal Length/Width",
         "x": 0.5
        },
        "xaxis": {
         "linecolor": "black",
         "linewidth": 3,
         "showline": true,
         "showspikes": true,
         "spikecolor": "red",
         "spikethickness": 2,
         "title": {
          "standoff": 10,
          "text": "SepalWidthCm"
         }
        },
        "yaxis": {
         "linecolor": "black",
         "linewidth": 3,
         "showline": true,
         "showspikes": true,
         "spikecolor": "red",
         "spikethickness": 2,
         "title": {
          "standoff": 10,
          "text": "SepalLengthCm"
         }
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import plotly.graph_objects as go\n",
    "#adding figure for Length/Width visualization\n",
    "fig1=go.Figure()\n",
    "#adding traces\n",
    "fig1.add_trace(go.Scatter(x=df_raw[df_raw.setosa == 1].sepal_width, y=df_raw[df_raw.setosa == 1].sepal_length, name='Setosa',\n",
    "                        mode='markers', marker_color='rgb(52, 152, 219)',\n",
    "                        marker_symbol='star-triangle-up', marker_opacity=0.8,\n",
    "                        hovertemplate=\"<b>SepalWidthCm:</b> %{x} <br><b>SepalLengthCm:</b> %{y}\"))\n",
    "fig1.add_trace(go.Scatter(x=df_raw[df_raw.setosa != 1].sepal_width, y=df_raw[df_raw.setosa != 1].sepal_length, name='Non-Setosa',\n",
    "                        mode='markers', marker_color='rgb(170, 128, 255)',\n",
    "                        marker_symbol='hexagram', marker_opacity=0.8,\n",
    "                        hovertemplate=\"<b>SepalWidthCm:</b> %{x} <br><b>SepalLengthCm:</b> %{y}\"))\n",
    "\n",
    "#customizing figure\n",
    "fig1.update_traces(mode='markers', marker_line_width=1.5, marker_size=12)\n",
    "fig1.update_layout(template='plotly_white', xaxis=dict(title_text='SepalWidthCm', title_standoff=10),\n",
    "                   yaxis=dict(title_text='SepalLengthCm', title_standoff=10),\n",
    "                   title_text='Sepal Length/Width', title_x=0.5)\n",
    "fig1.update_xaxes(showline=True, linewidth=3, linecolor='black',\n",
    "                  showspikes=True, spikecolor='red', spikethickness=2)\n",
    "fig1.update_yaxes(showline=True, linewidth=3, linecolor='black',\n",
    "                  showspikes=True, spikecolor='red', spikethickness=2)\n",
    "#showing figure\n",
    "fig1.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.4 ('.venv': poetry)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "f70e5568322297c701f68d8cb002dc8dbcefa682adbbc7bc1b0f245279d2a68d"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
